package functionalInterface;

import com.sun.org.apache.xpath.internal.SourceTree;
import sun.plugin.javascript.navig.LinkArray;

import java.util.*;
import java.util.function.*;

/**
 * Created with IntelliJ IDEA.
 * 类名：MainTest
 * 开发人员: CoderJu
 * 创建时间: 2019/3/4 22:56
 * 描述:
 * 版本：V1.0
 */
public class MainTest {
    public static void main(String[] args) {
        System.out.println("------BiConsumer------");
        BiConsumer<String,String> biConsumer = (x,y)-> System.out.println(x+"--------------"+y);
        BiConsumer<String,String> biConsumer2 = (x,y)-> System.out.println(x+">>>>>>>>"+y);
        biConsumer.accept("JACK","JAVA8");
        biConsumer.andThen(biConsumer2).accept("biConsumer2","JAVA8");
        System.out.println("------BiConsumer------");

        System.out.println("------BiFunction------");
        BiFunction<Integer,Integer,Integer>  biFunction = (x, y)-> {return  x+y;};
        int result =  biFunction.apply(1,2);
        System.out.println("result:"+result);
        Function<Integer,Integer> function = (x)->{return (x*5);};
        System.out.println("andThen:"+biFunction.andThen(function).apply(8,9));
        System.out.println("------BiFunction------");

        System.out.println("------BinaryOperator------");
        BinaryOperator<Integer> binaryOperator = (x,y)->x*y;
        System.out.println("BinaryOperator:"+binaryOperator.apply(3,8));
        Function<Integer,Integer> function1 = (x)->x*8;
        System.out.println("BinaryOperator andThen:" + binaryOperator.andThen(function1).apply(8,10));
        BinaryOperator<Integer> bi = BinaryOperator.maxBy(Comparator.naturalOrder());
        System.out.println("BinaryOperator maxBy:" + (bi.apply(100,99)));
        System.out.println("------BinaryOperator------");

        System.out.println("------BiPredicate------");
        BiPredicate<String,String> biPredicate = (x,y)-> x.equals(y);
        BiPredicate<String,String> biPredicate1 = (x,y)-> (x+"2").equals(y);
        System.out.println("False>>>>>:"+biPredicate.test("a","b"));
        System.out.println("True>>>>>:"+biPredicate.test("a","a"));
        //biPredicate和biPredicate1是否同时满足
        System.out.println("and >>>>>:"+biPredicate.and(biPredicate1).test("xxx","xxx2"));
        //negate表示非运算，类似"!"
        System.out.println("negate >>>>>:"+biPredicate.negate().test("a","a"));
        System.out.println("negate >>>>>:"+biPredicate.negate().test("a","c"));
        //or或者
        System.out.println("or >>>>>:"+biPredicate.or(biPredicate1).test("xxx","xxx2"));
        System.out.println("or >>>>>:"+biPredicate.or(biPredicate1).test("xxx","xx"));
        System.out.println("------BiPredicate------");

        System.out.println("------BooleanSupplier------");
        BooleanSupplier booleanSupplier = ()->true;
        System.out.println(" booleanSupplier :" + booleanSupplier.getAsBoolean());
        int x=2;
        int y=3;
        BooleanSupplier booleanSupplier1 = ()->x>y;
        System.out.println(" booleanSupplier1 :" + booleanSupplier1.getAsBoolean());
        System.out.println("------BooleanSupplier------");

        System.out.println("------Consumer------");
        Consumer consumer = (m)-> System.out.println(">>>>>"+m);
        consumer.accept("这是第一个consumer");
        consumer.andThen(consumer).accept("This is second");
        System.out.println("------Consumer------");

        System.out.println("------DoubleBinaryOperator------");
        DoubleBinaryOperator doubleBinaryOperator = (a,b)->{
            if(a>b){
               return  a-b;
            }else{
                return  b-a;
            }
        };
        double d =  doubleBinaryOperator.applyAsDouble(6.1,9.1);
        double d1 =  doubleBinaryOperator.applyAsDouble(61.1,9.1);
        System.out.println("doubleBinaryOperator d>>"+d);
        System.out.println("doubleBinaryOperator d1>>"+d1);
        System.out.println("------DoubleBinaryOperator------");

        System.out.println("------DoubleConsumer------");
        DoubleConsumer doubleConsumer = System.out::println;
        doubleConsumer.accept(6.5);
        doubleConsumer.andThen(doubleConsumer).accept(18);
        System.out.println("------DoubleConsumer------");

        System.out.println("------DoubleFunction------");
        DoubleFunction doubleFunction = (w)->{
            if (w>0){
                System.out.println("正double数据");
                return  w*2;
            }else{
                System.out.println("负double数据");
                return  w*2;
            }
        };
        System.out.println("DoubleFunction >>>>"+doubleFunction.apply(18));
        System.out.println("DoubleFunction >>>>"+doubleFunction.apply(-18));
        System.out.println("------DoubleFunction------");

        System.out.println("------DoublePredicate------");
        DoublePredicate doublePredicate = qw->qw>0;
        DoublePredicate doublePredicate2 = qe->qe>0;
        System.out.println("DoublePredicate test====="+doublePredicate.test(-11));
        System.out.println("DoublePredicate negate ====="+doublePredicate.negate().test(-11));
        System.out.println("DoublePredicate  and ====="+doublePredicate.and(doublePredicate2).test(111));
        System.out.println("DoublePredicate  or ====="+doublePredicate.or(doublePredicate2).test(111));
        System.out.println("------DoublePredicate------");

        System.out.println("------DoubleSupplier------");
        DoubleSupplier doubleSupplier=()->8.0;
        double qe = 8.0;
        double qt = 9.7;
        DoubleSupplier doubleSupplier1=()->qe*qt;
        System.out.println("DoubleSupplier>>>"+doubleSupplier.getAsDouble());
        System.out.println("doubleSupplier1>>>"+doubleSupplier1.getAsDouble());
        System.out.println("------DoubleSupplier------");

        System.out.println("------DoubleToIntFunction------");
        int x1= 8;
        DoubleToIntFunction doubleToIntFunction = (qy)->{
            return (int)(qy*x1);
        };
        System.out.println("doubleToIntFunction>>>"+doubleToIntFunction.applyAsInt(8.95));
        System.out.println("------DoubleToIntFunction------");

        System.out.println("------DoubleToLongFunction------");
        long x2= 8;
        DoubleToLongFunction doubleToLongFunction = (qy)->{
            return (long) qy*x2;
        };
        System.out.println("DoubleToLongFunction>>>"+doubleToLongFunction.applyAsLong(9.5858));
        System.out.println("------DoubleToLongFunction------");

        System.out.println("------DoubleUnaryOperator------");
        DoubleUnaryOperator doubleUnaryOperator = (qu)->qu*2;
        DoubleUnaryOperator doubleUnaryOperator1 = (qu)->qu+2;
        System.out.println("DoubleUnaryOperator applyAsLong >>>"+doubleUnaryOperator.applyAsDouble(9.00));
        System.out.println("DoubleUnaryOperator compose >>>"+doubleUnaryOperator.compose(doubleUnaryOperator1).applyAsDouble(18.0));
        System.out.println("DoubleUnaryOperator andThen >>>"+doubleUnaryOperator.andThen(doubleUnaryOperator).applyAsDouble(16.0));
        System.out.println("------DoubleUnaryOperator------");

        System.out.println("------Function------");
        Function<String,String> stringFunction = qi->qi+"   Hello Word";
        Function<String,String> stringFunction1 = qo->qo+"   How Are You?";
        System.out.println("Function >>>>>>"+stringFunction.apply("JACK"));
        System.out.println("Function andThen>>>>>>"+stringFunction.andThen(stringFunction1).apply("Tom"));
        System.out.println("Function compose>>>>>>"+stringFunction.compose(stringFunction1).apply("Tony"));
        System.out.println("------Function------");

        System.out.println("------IntBinaryOperator------");
        IntBinaryOperator binaryOperator1=(qp,qa)->{
            if (qp>qa){
                return qp-qa;
            }else {
                return qa-qp;
            }
        };
        System.out.println("IntBinaryOperator >>>>>>"+binaryOperator1.applyAsInt(8,5));
        System.out.println("IntBinaryOperator >>>>>>"+binaryOperator1.applyAsInt(1,5));
        System.out.println("------IntBinaryOperator------");

        System.out.println("------IntConsumer------");
        IntConsumer intConsumer = qs->{
            System.out.println(qs*100000);
        };
        IntConsumer intConsumer1 = qd->{
            System.out.println(">>>>>"+qd*15);
        };
        intConsumer.accept(789);
        intConsumer1.andThen(intConsumer).accept(8);
        System.out.println("------IntConsumer------");

        System.out.println("------IntFunction------");
        IntFunction<Double> intFunction = qf->{
            return x*0.88;
        };
        System.out.println("IntFunction >>>>>"+intFunction.apply(5));
        System.out.println("------IntFunction------");

        System.out.println("------IntPredicate------");
        IntPredicate intPredicate = qg->{
            return qg>100;
        };
        IntPredicate intPredicate1 = qh->{
            return qh<100;
        };
        System.out.println("IntPredicate Test>>>>"+intPredicate.test(99));
        System.out.println("IntPredicate Test>>>>"+intPredicate.test(150));
        System.out.println("IntPredicate negate>>>>"+intPredicate.negate().test(150));
        System.out.println("IntPredicate and>>>>"+intPredicate.and(intPredicate1).test(150));
        System.out.println("IntPredicate or>>>>"+intPredicate.or(intPredicate1).test(150));
        System.out.println("------IntPredicate------");

        System.out.println("------IntSupplier------");
        IntSupplier intSupplier = ()->{
                double str = 11.0;
                return (int)str;
        };
        System.out.println("IntSupplier >>>>"+intSupplier.getAsInt());
        System.out.println("------IntSupplier------");


        System.out.println("------IntToDoubleFunction------");
        IntToDoubleFunction intToDoubleFunction = qj->{
            return qj*0.05;
        };
        System.out.println("intToDoubleFunction >>>>"+intToDoubleFunction.applyAsDouble(19));
        System.out.println("------IntToDoubleFunction------");

        System.out.println("------IntToLongFunction------");
        IntToLongFunction intToLongFunction = qk->{
            long ll = (long)2.501 ;
            return qk*ll;
        };
        System.out.println("IntToLongFunction >>>>"+intToLongFunction.applyAsLong(182));
        System.out.println("------IntToLongFunction------");

        System.out.println("------IntUnaryOperator------");
        IntUnaryOperator intUnaryOperator = ql->{
            return ql *100;
        };
        IntUnaryOperator intUnaryOperator1 = qz->{
            return qz *500;
        };
        System.out.println("IntToLongFunction >>>>"+intUnaryOperator.applyAsInt(52));
        System.out.println("IntToLongFunction >>>>"+intUnaryOperator1.applyAsInt(52));
        System.out.println("IntToLongFunction andThen >>>>"+intUnaryOperator.andThen(intUnaryOperator1).applyAsInt(52));
        System.out.println("IntToLongFunction compose >>>>"+intUnaryOperator.compose(intUnaryOperator1).applyAsInt(52));
        System.out.println("------IntUnaryOperator------");

        System.out.println("------LongBinaryOperator------");
        LongBinaryOperator longBinaryOperator = (qx,qc)->{
            if (qx>qc){
               return qx - qc;
            }else{
               return qx*qc;
            }
        };
        System.out.println("LongBinaryOperator >>>>"+longBinaryOperator.applyAsLong(18,9));
        System.out.println("LongBinaryOperator >>>>"+longBinaryOperator.applyAsLong(80,90));
        System.out.println("------LongBinaryOperator------");

        System.out.println("------LongConsumer------");
        LongConsumer longConsumer = (qv)-> System.out.println(">>>>>>>"+qv);
        LongConsumer longConsumer1 = (qb)-> System.out.println("<<<<<<"+qb);
        longConsumer.accept(8);
        longConsumer1.andThen(longConsumer).accept(999);
        System.out.println("------LongConsumer------");

        System.out.println("------LongFunction------");
        LongFunction longFunction = qn->{
            return String.valueOf(qn);
        };
        System.out.println("LongFunction >>>>"+ longFunction.apply(12333333));
        System.out.println("LongFunction type>>>>"+ (longFunction.apply(12333333)).getClass().toString());
        System.out.println("------LongFunction------");

        System.out.println("------LongPredicate------");
        LongPredicate longPredicate = qm->{
            if(qm>100){
                return true;
            }else{
                return false;
            }
        };
        LongPredicate longPredicate1 = wq->{
            if(wq<100){
                return true;
            }else{
                return false;
            }
        };
        System.out.println("LongPredicate >>>>"+ longPredicate.test(10000000));
        System.out.println("LongPredicate >>>>"+ longPredicate.test(10));
        System.out.println("LongPredicate >>>>"+ longPredicate.negate().test(10));
        System.out.println("LongPredicate and >>>>"+ longPredicate.and(longPredicate).test(100));
        System.out.println("LongPredicate or >>>>"+ longPredicate.or(longPredicate).test(100));
        System.out.println("------LongPredicate------");

        System.out.println("------LongSupplier------");
        LongSupplier longSupplier = ()->{
            return Long.valueOf("111111");
        };
        System.out.println("LongSupplier >>>>"+ longSupplier.getAsLong());
        System.out.println("------LongSupplier------");

        System.out.println("------LongToDoubleFunction------");
        LongToDoubleFunction longToDoubleFunction =  (ww)->{
            return Double.valueOf(ww);
        };
        System.out.println("longToDoubleFunction >>>>"+ longToDoubleFunction.applyAsDouble(1000000));
        System.out.println("------LongToDoubleFunction------");

        System.out.println("------LongToIntFunction------");
        LongToIntFunction longToIntFunction =  (wr)->{
            return (int)wr;
        };
        System.out.println("longToDoubleFunction >>>>"+ longToIntFunction.applyAsInt(9999999));
        System.out.println("------LongToIntFunction------");

        System.out.println("------LongUnaryOperator------");
        LongUnaryOperator longUnaryOperator = (wt)->{
            return (long)wt*100;
        };
        LongUnaryOperator longUnaryOperator1 = (wt)->{
            return (long)wt+10;
        };
        System.out.println("------LongUnaryOperator>>>>"+longUnaryOperator.applyAsLong(1888));
        System.out.println("LongUnaryOperator andThen>>>"+longUnaryOperator.andThen(longUnaryOperator1).applyAsLong(18));
        System.out.println("LongUnaryOperator compose>>>"+longUnaryOperator.compose(longUnaryOperator1).applyAsLong(18));
        System.out.println("LongUnaryOperator identity>>>"+LongUnaryOperator.identity().applyAsLong(18));
        System.out.println("-----LongUnaryOperator------");

        System.out.println("-----ObjDoubleConsumer------");
        Map<String,Double> map = new HashMap<String,Double>();
        ObjDoubleConsumer objDoubleConsumer=(wy,wu)->{
            map.put(String.valueOf(wy),wu);
            System.out.println("ObjDoubleConsumer>>>>"+map.get(wy));
        };
        objDoubleConsumer.accept("111111",10.5);
        System.out.println("-----ObjDoubleConsumer------");

        System.out.println("-----ObjIntConsumer------");
        ObjIntConsumer objIntConsumer = (wi,wo)->{
            System.out.println("ObjIntConsumer>>>>"+wi+"||wi class:"+wi.getClass().toString());
            System.out.println("ObjIntConsumer>>>>"+wo+"||wi class"+wo);
        };
        List list = new ArrayList();
        list.add("1");
        objIntConsumer.accept(list,80);
        System.out.println("-----ObjIntConsumer------");

        System.out.println("-----ObjLongConsumer------");
        ObjLongConsumer objLongConsumer = (wp,wa)->{
            System.out.println("objLongConsumer>>>>"+wp+"||wi class:"+wp.getClass().toString());
            System.out.println("objLongConsumer>>>>"+wa+"||wi class"+wa);
        };
        Map map1 = new HashMap();
        map1.put("1","1111");
        objLongConsumer.accept(map1,1000);
        System.out.println("-----ObjLongConsumer------");

        System.out.println("-----Predicate------");
        Map map2 = new HashMap();
        map2.put("1","1111");
        Predicate predicate=ws->{
            System.out.println("Step 1");
            if(map2.get("1").equals(ws)){
               return false;
            }else{
                return true;
            }
        };
        Predicate predicate1=wd->{
            System.out.println("Step 2");
            if (wd.equals("2")){
                return false;
            }else {
                return true;
            }
        };
        System.out.println("Predicate>>>>"+ predicate.test(2222));
        System.out.println("Predicate negate >>>>"+ predicate.negate().test(2222));
        System.out.println("Predicate and >>>>"+ predicate.and(predicate1).test(222));
        System.out.println("Predicate or >>>>"+ predicate.or(predicate1).test(22));
        System.out.println("-----Predicate------");

        System.out.println("-----Supplier------");
        Supplier supplier = ()->{
            Map map3 = new HashMap();
            map3.put("1","张三");
            return map3;
        };
        System.out.println(" Supplier >>>>"+supplier.get());
        System.out.println("-----Supplier------");

        System.out.println("-----ToDoubleBiFunction------");
        List list1 = new ArrayList();
        list1.add(180.0);
        Map map4 = new HashMap();
        map4.put("a",2000.0);
        ToDoubleBiFunction toDoubleBiFunction=(wf,wg)->{
            return ((double)(((ArrayList)wf).get(0)))+((double)(((HashMap)wg).get("a")));
        };
        System.out.println("ToDoubleBiFunction >>>>>>"+toDoubleBiFunction.applyAsDouble(list1,map4));
        System.out.println("-----ToDoubleBiFunction------");

        System.out.println("-----ToIntBiFunction------");
        List list2 = new ArrayList();
        list2.add(1800);
        Map map5 = new HashMap();
        map5.put("a",20000);
        ToIntBiFunction toIntBiFunction=(wf,wg)->{
            return ((int)(((ArrayList)wf).get(0)))+((int)(((HashMap)wg).get("a")));
        };
        System.out.println("ToIntBiFunction >>>>>>"+toIntBiFunction.applyAsInt(list2,map5));
        System.out.println("-----ToIntBiFunction------");

        System.out.println("-----ToIntFunction------");
        Hashtable hashtable = new Hashtable();
        hashtable.put("888",888);
        ToIntFunction toIntFunction = wh->{
            return (int)((Hashtable)(wh)).get("888");
        };
        System.out.println("ToIntFunction >>>>>>"+toIntFunction.applyAsInt(hashtable));
        System.out.println("-----ToIntFunction------");


        System.out.println("-----ToLongBiFunction------");
        List list3 = new ArrayList();
        list3.add(1800);
        Map map6 = new HashMap();
        map6.put("a",20000);
        ToLongBiFunction longBiFunction = (wj,wk)->{
            long t1 = 0;
            long t2 = 0;
            if (wj instanceof ArrayList){
                t1 = (long)((ArrayList) wj).get(0);
            }else if (wk instanceof HashMap){
                t2 = (long)((HashMap) wk).get("a");
            }
            return t1+t2;
        };
        System.out.println("ToLongBiFunction >>>>>>"+toIntBiFunction.applyAsInt(list3,map6));
        System.out.println("-----ToLongBiFunction------");

        System.out.println("-----ToLongFunction------");
        ToLongFunction toLongFunction = wl->{
            long t1 = 0;
            if (wl instanceof ArrayList){
                t1 = (long)((int)(((ArrayList) wl).get(0)));
            }else if (wl instanceof HashMap){
                t1 = (long)((int)((HashMap) wl).get("a"));
            }
            return t1;
        };
        System.out.println("ToLongFunction list3 >>>>>>"+toLongFunction.applyAsLong(list3));
        System.out.println("ToLongFunction  map6 >>>>>>"+toLongFunction.applyAsLong(map6));
        System.out.println("-----ToLongFunction------");

        System.out.println("-----UnaryOperator------");
        List<String> list4 = new ArrayList<>();
        list4.add("1");
        list4.add("2");
        List<String> list5 = (ArrayList)(UnaryOperator.identity().apply(list4));
        list5.stream().forEach(wx->System.out.println(">>>>>"+wx));
        System.out.println("-----UnaryOperator------");
















    }
}
